package com.itheima.apis.category.fallback;

import com.itheima.apis.category.ICategoryClient;
import com.itheima.model.book.dtos.CategoryAdminDto;
import com.itheima.model.book.dtos.CategorySaveDto;
import com.itheima.model.common.dtos.ResponseResult;
import com.itheima.model.common.enums.AppHttpCodeEnum;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * ICategoryClient降级处理
 * 当book-service不可用时，返回默认响应
 * 
 * @author itheima
 */
@Component
public class ICategoryClientFallBack implements ICategoryClient {

    @Override
    public ResponseResult getCategoryTree() {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "分类服务暂时不可用，无法获取分类树");
    }

    // ==================== 管理端接口降级 ====================

    @Override
    public ResponseResult adminListCategories(CategoryAdminDto dto) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "分类服务暂时不可用，无法查询分类列表");
    }

    @Override
    public ResponseResult adminGetCategoryById(Integer id) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "分类服务暂时不可用，无法获取分类详情");
    }

    @Override
    public ResponseResult adminAddCategory(CategorySaveDto dto) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "分类服务暂时不可用，无法新增分类");
    }

    @Override
    public ResponseResult adminUpdateCategory(Integer id, CategorySaveDto dto) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "分类服务暂时不可用，无法更新分类");
    }

    @Override
    public ResponseResult adminDeleteCategory(Integer id) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "分类服务暂时不可用，无法删除分类");
    }

    @Override
    public ResponseResult adminUpdateCategoryStatus(Integer id, Map<String, Integer> params) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "分类服务暂时不可用，无法更新分类状态");
    }

    @Override
    public ResponseResult adminGetParentCategories() {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "分类服务暂时不可用，无法获取父级分类列表");
    }
}

